package script.param;

import cn.hutool.core.util.HexUtil;
import com.gee.cloud.common.core.util.time.TimeUtil;
import com.gee.spring.cloud.aerospace.simulate.core.satellite.telemetry.TmFrameGenerator;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Map;

/**
 * @author gepengjun
 * @since 2024/7/10 14:07
 */
public class SateTime {

    static byte[] eval(TmFrameGenerator tmFrameGenerator, Map<String, String> scriptParamMap, String paramValue){
        String baseTimeStr = scriptParamMap.get("baseTime");
        String dateTimeFormat = scriptParamMap.get("dateTimeFormat");
        int multiOfMicros = Integer.parseInt(scriptParamMap.get("multiOfMicros"));
        LocalDateTime baseTime = TimeUtil.parse(baseTimeStr, dateTimeFormat);
        LocalDateTime sateTime = LocalDateTime.now().plus(tmFrameGenerator.getSateTimeOffset(), ChronoUnit.SECONDS);
        long sateTimeValue = ChronoUnit.MICROS.between(baseTime, sateTime) / multiOfMicros;
        return HexUtil.decodeHex(HexUtil.toHex(sateTimeValue));
    }
}
